package com.jcfy.project.module.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcfy.framework.aspectj.lang.annotation.Log;
import com.jcfy.framework.aspectj.lang.enums.BusinessType;
import com.jcfy.project.module.domain.TCategory;
import com.jcfy.project.module.service.ITCategoryService;
import com.jcfy.framework.web.controller.BaseController;
import com.jcfy.framework.web.domain.AjaxResult;
import com.jcfy.common.utils.poi.ExcelUtil;
import com.jcfy.framework.web.page.TableDataInfo;

/**
 * 类目Controller
 *
 * @author jiangfeng
 * @date 2020-08-05
 */
@RestController
@RequestMapping("/module/category" )
public class TCategoryController extends BaseController {
    @Autowired
    private ITCategoryService tCategoryService;

    /**
     * 查询类目列表
     */
    @PreAuthorize("@ss.hasPermi('module:category:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(TCategory tCategory) {
        startPage();
        List<TCategory> list = tCategoryService.selectTCategoryList(tCategory);
        return getDataTable(list);
    }

    /**
     * 导出类目列表
     */
    @PreAuthorize("@ss.hasPermi('module:category:export')" )
    @Log(title = "类目" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TCategory tCategory) {
        List<TCategory> list = tCategoryService.selectTCategoryList(tCategory);
        ExcelUtil<TCategory> util = new ExcelUtil<TCategory>(TCategory. class);
        return util.exportExcel(list, "category" );
    }

    /**
     * 获取类目详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:category:query')" )
    @GetMapping(value = "/{categoryId}" )
    public AjaxResult getInfo(@PathVariable("categoryId" ) Long categoryId) {
        return AjaxResult.success(tCategoryService.selectTCategoryById(categoryId));
    }

    /**
     * 新增类目
     */
    @PreAuthorize("@ss.hasPermi('module:category:add')" )
    @Log(title = "类目" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCategory tCategory) {
        return toAjax(tCategoryService.insertTCategory(tCategory));
    }

    /**
     * 修改类目
     */
    @PreAuthorize("@ss.hasPermi('module:category:edit')" )
    @Log(title = "类目" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCategory tCategory) {
        return toAjax(tCategoryService.updateTCategory(tCategory));
    }

    /**
     * 删除类目
     */
    @PreAuthorize("@ss.hasPermi('module:category:remove')" )
    @Log(title = "类目" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}" )
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(tCategoryService.deleteTCategoryByIds(categoryIds));
    }
}
